import axios from "axios";
import {STORE} from "@/scripts/account";

export const BookingStatus = {
    'WAREHOUSE': '库存中',
    'TRANSPORT': '运输中',
    'WAITING': '等待签收',
    'FINISHED': '已签收',
}
export const BookingStatusFilters = [
    {text:'库存中', value:'库存中'},
    {text:'运输中', value:'运输中'},
    {text:'等待签收', value:'等待签收'},
    {text:'已签收', value:'已签收'},
]

export const chooseTagType = (txt) => {
    if (txt == BookingStatus['WAREHOUSE']) {
        return 'warning'
    } else if (txt == BookingStatus['TRANSPORT']) {
        return 'success'
    } else if (txt == BookingStatus['WAITING']) {
        return 'danger'
    } else {
        return 'info'
    }
}


export const getBooking = (id, callback) => {
    axios.get('/booking/' + id).then((response) => {
        callback(response.data)
    })
}

export const getBookingList = (callback) => {
    axios.get('/booking').then((response) => {
        let rs = response.data
        for (let i = 0; i < rs.length; i++) {
            rs[i].status = BookingStatus[rs[i].status]
        }
        callback(rs)
    })
}

export const getBookingListByOperator = (callback) => {
    axios.get('/booking/operator/' + STORE.userState.data.username).then((response) => {
        let rs = response.data
        for (let i = 0; i < rs.length; i++) {
            rs[i].status = BookingStatus[rs[i].status]
        }
        callback(rs)
    })
}

export const getBookingListByWarehouse = (callback) => {
    axios.get('/booking/warehouse/' + STORE.userState.data.username).then((response) => {
        let rs = response.data
        for (let i = 0; i < rs.length; i++) {
            rs[i].status = BookingStatus[rs[i].status]
        }
        callback(rs)
    })
}


export const deleteBooking = (id, callback) => {
    axios.delete('/booking/' + id).then((response) => {
        callback(response.data);
    });
}

export const createBooking = (bookingData, callback) => {
    axios.post('/input', bookingData).then((response) => {
        callback(response.data)
    })
}

export const updateBooking = (bookingData, callback) => {
    axios.put('/booking/' + bookingData.oid, bookingData).then((response) => {
        callback(response.data ? 1 : 0);
    })
}

export const getBillList = (callback) => {
    axios.get('/booking/showmoney').then((response)=>{
        callback(response.data);
    })
}

// export const createBooking = (bookingData, callback) => {
//     axios.post('/booking', bookingData).then((response) => {
//         callback(response.data ? 1 : 0)
//     })
// }

export const getMoney = (weight, callback) => {
    axios.get('/input/money', {params: {weight: weight}}).then((response) => {
        callback(response.data);
    })
}